﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Holiday;
using B.S.DataBase.MyRead.API.DTOs;
using MediatR;
using System.Collections.Generic;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Holiday
{
    public class ApprovalCommandHarder : IRequestHandler<ApprovalCommand, APIResult<List<User>>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRepository<User> repository;

        public ApprovalCommandHarder(IMapper mapper, IBaseRepository<User> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }

        public Task<APIResult<List<User>>> Handle(ApprovalCommand request, CancellationToken cancellationToken)
        {
                APIResult<List<User>> result = new APIResult<List<User>>();
            result.Code= APIEnum.查询成功;
            result.Msg= APIEnum.查询成功.ToString();


            var list = repository.GetAll().Result.Where(x => x.DepId == request.DepId).ToList();

            if (list.Count>0)
            {
                list = list.Where(x => x.approvalId == (request.approvalId + 1)).ToList();
            }
            result.data= list;  

            return Task.FromResult(result);

        }
    }
}
